home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume3 / lib_term < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  51.4 KB

  1. From: "George W. Sherouse" <seismo!mcnc.CSNET!godot!sherouse>
  2. Subject: lib_term - datum entry using termcap
  3. Newsgroups: mod.sources
  4. Approved: jpn@panda.UUCP
  5.  
  6. Mod.sources:  Volume 3, Issue 102
  7. Submitted by: "George W. Sherouse" <seismo!mcnc.CSNET!godot!sherouse>
  8.  
  9.  
  10. --------------------------- cut here ----------------------------
  11. #! /bin/sh
  12. # This is a shell archive, meaning:
  13. # 1. Remove everything above the #! /bin/sh line.
  14. # 2. Save the resulting text in a file.
  15. # 3. Execute the file with /bin/sh (not csh) to create the files:
  16. #    README
  17. #    makefile
  18. #    term.l
  19. #    term.h
  20. #    ClearEOL.c
  21. #    GetBool.c
  22. #    GetFloat.c
  23. #    GetHospNum.c
  24. #    GetInt.c
  25. #    GetString.c
  26. #    InitTerm.c
  27. #    MenuPick.c
  28. #    PickOne.c
  29. #    StandOut.c
  30. #    TermRewind.c
  31. #    TermSetUp.c
  32. #    center.c
  33. #    examp.c
  34. #    gotoxy.c
  35. #    page.c
  36. #    underline.c
  37. # This archive created: Sat Jan 25 11:42:29 1986
  38. export PATH; PATH=/bin:$PATH
  39. echo shar: extracting "'README'" '(984 characters)'
  40. if test -f 'README'
  41. then
  42.     echo shar: will not over-write existing file "'README'"
  43. else
  44. sed 's/^    X//' << \SHAR_AND_ENJOY > 'README'
  45.     XThis directory contains the source for a library of bullet-proof
  46.     Xdatum-entry routines which uses the termcap library directly.  This
  47.     Xlibrary (which I call libterm) also contains simple cursor
  48.     Xmanipulation routines which make it a viable alternative to curses for
  49.     Xapplications which don't require the power and overhead of curses.
  50.     XAnother version exists which rides on top on curses (libc_term).
  51.     X
  52.     XThe code is rather a mess and in some cases rather inefficient.  That
  53.     Xis a statement not an apology.  This was some of my first C code and
  54.     Xhas been used extensively here and elsewhere with *NO* bug reports.
  55.     XThis same code was posted to net.sources about 18 months ago and a
  56.     Xtrickle of requests has continued since then.  If it ain't broke don't
  57.     Xfix it.
  58.     X
  59.     XPermission is granted to copy and redistribute this code as long as no
  60.     Xmoney changes hands and this notice and the authorship notes remain
  61.     Xintact.  Let me know if you find/fix any bugs.  Enjoy.
  62.     X
  63.     X- George
  64.     X<decvax!mcnc!godot!sherouse>
  65.     X
  66. SHAR_AND_ENJOY
  67. if test 984 -ne "`wc -c < 'README'`"
  68. then
  69.     echo shar: error transmitting "'README'" '(should have been 984 characters)'
  70. fi
  71. fi # end of overwriting check
  72. echo shar: extracting "'makefile'" '(1154 characters)'
  73. if test -f 'makefile'
  74. then
  75.     echo shar: will not over-write existing file "'makefile'"
  76. else
  77. sed 's/^    X//' << \SHAR_AND_ENJOY > 'makefile'
  78.     XINCDIR = /usr/include
  79.     XMANDIR = /usr/man/manl
  80.     XLIBDIR = /usr/local/lib
  81.     X
  82.     XCFLAGS = -O
  83.     X
  84.     XOBJS = ClearEOL.o GetBool.o GetFloat.o GetHospNum.o GetInt.o GetString.o\
  85.     X    InitTerm.o MenuPick.o PickOne.o StandOut.o TermRewind.o TermSetUp.o\
  86.     X    center.o gotoxy.o page.o underline.o
  87.     X
  88.     Xlibterm.a: $(OBJS) makefile
  89.     X    ar rvu libterm.a $(OBJS)
  90.     X    ranlib libterm.a
  91.     X
  92.     XClearEOL.o: ClearEOL.c makefile
  93.     XGetBool.o: GetBool.c makefile
  94.     XGetFloat.o: GetFloat.c makefile
  95.     XGetHospNum.o: GetHospNum.c makefile
  96.     XGetInt.o: GetInt.c makefile
  97.     XGetString.o: GetString.c makefile
  98.     XInitTerm.o: InitTerm.c makefile
  99.     XMenuPick.o: MenuPick.c makefile
  100.     XPickOne.o: PickOne.c makefile
  101.     XStandOut.o: StandOut.c makefile
  102.     XTermRewind.o: TermRewind.c makefile
  103.     XTermSetUp.o: TermSetUp.c makefile
  104.     Xcenter.o: center.c makefile
  105.     Xgotoxy.o: gotoxy.c makefile
  106.     Xpage.o: page.c makefile
  107.     Xunderline.o: underline.c makefile
  108.     X
  109.     Xexamp: examp.c $(INCDIR)/term.h $(LIBDIR)/libterm.a makefile
  110.     X    cc $(CFLAGS) -o examp examp.c -lterm -ltermcap
  111.     X
  112.     Xinstall: libterm.a
  113.     X    mv libterm.a $(LIBDIR)
  114.     X    ranlib $(LIBDIR)/libterm.a
  115.     X    cp term.h $(INCDIR)
  116.     X
  117.     Xinstall_man: term.l
  118.     X    cp term.l $(MANDIR)
  119.     X    chmod 444 $(MANDIR)/term.l
  120.     X
  121.     Xclean:
  122.     X    rm -f *.o a.out core libterm.a
  123. SHAR_AND_ENJOY
  124. if test 1154 -ne "`wc -c < 'makefile'`"
  125. then
  126.     echo shar: error transmitting "'makefile'" '(should have been 1154 characters)'
  127. fi
  128. fi # end of overwriting check
  129. echo shar: extracting "'term.l'" '(5472 characters)'
  130. if test -f 'term.l'
  131. then
  132.     echo shar: will not over-write existing file "'term.l'"
  133. else
  134. sed 's/^    X//' << \SHAR_AND_ENJOY > 'term.l'
  135.     X.TH TERM L "Radiation Oncology, NCMH"
  136.     X.UC 4
  137.     X.SH NAME
  138.     Xterm \- "crash-proof" datum entry routines using termcap(3x)
  139.     X.SH SYNOPSIS
  140.     X#include <term.h>
  141.     X.sp
  142.     X.B cc
  143.     X[ flags ] files
  144.     X.B \-lterm \-ltermcap
  145.     X[ libraries ]
  146.     X.SH DESCRIPTION
  147.     XThese routines look after datum entry for the basic datum
  148.     Xtypes and provide some cursor control.
  149.     XA call to
  150.     X.I InitTerm
  151.     Xinitializes the 
  152.     X.I term
  153.     Xpackage by 
  154.     Xgetting the terminal type from environment variable TERM
  155.     Xand by reading the appropriate 
  156.     X.I termcap
  157.     Xentry.
  158.     XIn typical use, the calling program would paint a screen
  159.     Xand place the cursor at the beginning of a datum field
  160.     Xusing 
  161.     X.I page, gotoxy,
  162.     Xand
  163.     X.I printf
  164.     Xand would then call the appropriate 
  165.     X.I term
  166.     Xroutine to enter or edit that datum.
  167.     XThe field is highlighted using underline mode and the default value, if any,
  168.     Xis displayed.
  169.     XThe user may then enter a new value of the datum under strict field size
  170.     Xenforcement or accept the default.
  171.     XAcceptance of the displayed value is indicated by a RETURN.
  172.     XThe default value can be retrieved by ^X.
  173.     XNo abort is possible.
  174.     XWhen the value is accepted, the field is rewritten in normal mode and with the
  175.     Xnew value of the datum, and the cursor is left at the end of the field.
  176.     X
  177.     XExceptions to the above are
  178.     X.I GetBool
  179.     Xfor which valid inputs are n, N, y, Y, SPACE, and RETURN, for
  180.     Xno, yes, toggle, and accept respectively,
  181.     X.I PickOne
  182.     Xwhich understands ^ for previous value, SPACE for next value, and RETURN
  183.     Xfor accept,
  184.     Xand
  185.     X.I MenuPick
  186.     Xwhich understands ^ for previous value, SPACE for next value, 
  187.     X> for next page, and RETURN
  188.     Xfor accept.
  189.     X
  190.     XMagic cookies are dealt with
  191.     Xproperly but with the result that the 
  192.     Xfield on the screen is wider
  193.     Xthan the requested datum field
  194.     X.I "during entry".
  195.     XThe requested field size is used when the field is rewritten
  196.     Xin normal mode after acceptance
  197.     Xof a datum value.
  198.     XThis is a feature of
  199.     X.I term
  200.     Xand a bug in the terminals with magic cookies.
  201.     X.I Curses(3x)
  202.     Xdeals with this problem by just not allowing standout mode.
  203.     XWhich would you rather buy?
  204.     X.SH SEE ALSO
  205.     Xtermcap(3x)
  206.     X.br
  207.     Xc_term(l), if you have it
  208.     X.SH AUTHOR
  209.     X.nf
  210.     XGeorge W. Sherouse
  211.     XRadiation Oncology
  212.     XNorth Carolina Memorial Hospital
  213.     XUniversity of North Carolina, Chapel Hill
  214.     X.SH FUNCTIONS
  215.     XInitialize term.
  216.     XReturns 0 if successful, -1 if getenv fails, -2 if tgetent cannot
  217.     Xopen termcap file, -3 if tgetent cannot find entry for terminal.
  218.     XIf the return is not zero, do not pass GO.
  219.     X.br
  220.     X    int InitTerm();
  221.     X
  222.     XGet a floating point number.  Imagine %(field_width).(places)f
  223.     Xin a printf.
  224.     X.br
  225.     X    float GetFloat(default, field_width, places);
  226.     X.br
  227.     X    float default;
  228.     X.br
  229.     X    int field_width;
  230.     X.br
  231.     X    int places;
  232.     X
  233.     XGet an integer.
  234.     X.br
  235.     X    int GetInt(default, field_width);
  236.     X.br
  237.     X    int default;
  238.     X.br
  239.     X    int field_width;
  240.     X
  241.     XGet a boolean.
  242.     X.br
  243.     X    int GetBool(default);
  244.     X.br
  245.     X    int default;
  246.     X
  247.     XGet a string.  String should be at least field_size + 1 long
  248.     Xto accomodate the appended null.  Null_ok is a boolean which
  249.     Xdeclares whether or not a string of length zero is acceptable.
  250.     X.br
  251.     X    void GetString(string, field_size, null_ok);
  252.     X.br
  253.     X    char *string;
  254.     X.br
  255.     X    int field_size;
  256.     X.br
  257.     X    int null_ok;
  258.     X
  259.     XGet a hospital number in the format 00-00-00.
  260.     X.br
  261.     X    void GetHospNum(hosp_num);
  262.     X.br
  263.     X    char *hosp_num
  264.     X
  265.     XPick one string from a list of strings by displaying one choice at a time in
  266.     Xthe field.
  267.     X.br
  268.     X    int PickOne(list, choice_count);
  269.     X.br
  270.     X    char **list;
  271.     X.br
  272.     X    int choice_count;
  273.     X
  274.     XA full-screen version of PickOne.  The page is cleared, the prompt is displayed
  275.     Xat the top of the page and the first <some number> choices are displayed.
  276.     XThe user may step through the choices with ^ and SPACE.
  277.     XIf there are more than <some number> choices, the user may also change pages
  278.     Xwith >.
  279.     XRETURN accepts currently highlighted value.
  280.     X.br
  281.     X    int MenuPick(prompt, list, choice_count);
  282.     X.br
  283.     X    char *prompt;
  284.     X.br
  285.     X    char **list;
  286.     X.br
  287.     X    int choice_count;
  288.     X
  289.     XClear the screen.
  290.     X.br
  291.     X    void page();
  292.     X
  293.     XMove cursor.  Coordinates are 1-indexed from upper left.
  294.     X.br
  295.     X    void gotoxy(col, line);
  296.     X.br
  297.     X    int col;
  298.     X.br
  299.     X    int line;
  300.     X
  301.     XClear to end of line.
  302.     X.br
  303.     X    void ClearEOL();
  304.     X
  305.     XPrint string centered on line.  Mode == 0 requests normal print, == 1 requests
  306.     Xunderline, and == 2 requests standout.
  307.     X.br
  308.     X    void center(line, string, mode);
  309.     X.br
  310.     X    int line;
  311.     X.br
  312.     X    char *string;
  313.     X.br
  314.     X    int mode;
  315.     X
  316.     XSet or clear standout mode.  Not very useful at the applications level.
  317.     X.br
  318.     X    void StandOut(on_or_off);
  319.     X.br
  320.     X    int on_or_off;
  321.     X
  322.     XSet or clear underline mode.  Not very useful at the applications level.
  323.     X.br
  324.     X    void underline(on_or_off);
  325.     X.br
  326.     X    int on_or_off;
  327.     X
  328.     XIssue some backspaces.  Not very interesting at the applications level.
  329.     X.br
  330.     X    void TermRewind(count);
  331.     X.br
  332.     X    int count;
  333.     X
  334.     XPlace stdin into raw mode with no echo on odd calls and restore original modes
  335.     Xon even calls.
  336.     XReturn the terminal's erase character.
  337.     XNot intended for use at the applications level.
  338.     X.br
  339.     X    char TermSetUp();
  340.     X.SH BUGS
  341.     XMany sorts of stupidity are not checked for.
  342.     XThese include but are not limited to string longer than terminal width in
  343.     X.I center,
  344.     Xline or col out of bounds in
  345.     X.I center
  346.     Xor
  347.     X.I gotoxy,
  348.     Xfractional part longer than field_size in
  349.     X.I GetFloat,
  350.     Xand 0 or negative field_size anywhere.
  351.     X
  352.     XSome unreasonable assumptions are made regarding sanity in the termcap.
  353.     XYou will know what they are if you violate them.
  354.     XI apologize in advance.
  355.     X
  356.     X.I GetFloat
  357.     Xdoes not support scientific notation.
  358.     XIt also does not let you back up over the decimal point once it has placed
  359.     Xit.
  360.     XThis is no great hardship since you can always ^X to restart.
  361.     X
  362.     XSome of the code is a little ugly, having been hacked unmercifully through many
  363.     Xrevisions.
  364.     XIt does seem to work, though.
  365. SHAR_AND_ENJOY
  366. if test 5472 -ne "`wc -c < 'term.l'`"
  367. then
  368.     echo shar: error transmitting "'term.l'" '(should have been 5472 characters)'
  369. fi
  370. fi # end of overwriting check
  371. echo shar: extracting "'term.h'" '(263 characters)'
  372. if test -f 'term.h'
  373. then
  374.     echo shar: will not over-write existing file "'term.h'"
  375. else
  376. sed 's/^    X//' << \SHAR_AND_ENJOY > 'term.h'
  377.     Xvoid ClearEOL();
  378.     Xint GetBool();
  379.     Xfloat GetFloat();
  380.     Xvoid GetHospNum();
  381.     Xint GetInt();
  382.     Xvoid GetString();
  383.     Xint InitTerm();
  384.     Xint MenuPick();
  385.     Xint PickOne();
  386.     Xvoid StandOut();
  387.     Xvoid TermRewind();
  388.     Xchar TermSetUp();
  389.     Xvoid center();
  390.     Xvoid gotoxy();
  391.     Xvoid page();
  392.     Xvoid underline();
  393. SHAR_AND_ENJOY
  394. if test 263 -ne "`wc -c < 'term.h'`"
  395. then
  396.     echo shar: error transmitting "'term.h'" '(should have been 263 characters)'
  397. fi
  398. fi # end of overwriting check
  399. echo shar: extracting "'ClearEOL.c'" '(832 characters)'
  400. if test -f 'ClearEOL.c'
  401. then
  402.     echo shar: will not over-write existing file "'ClearEOL.c'"
  403. else
  404. sed 's/^    X//' << \SHAR_AND_ENJOY > 'ClearEOL.c'
  405.     X
  406.     Xvoid ClearEOL()
  407.     X
  408.     X/*
  409.     X ---------------------------------------------------------------------------
  410.     X 
  411.     X   Last revision - 
  412.     X     30 March 1984 - GWS
  413.     X 
  414.     X 
  415.     X   NAME
  416.     X     ClearEOL - clear to the end of line
  417.     X 
  418.     X   SYNOPSIS
  419.     X    void ClearEOL() 
  420.     X 
  421.     X   DESCRIPTION
  422.     X    Uses termcap(3x) routines to clear terminal screen. 
  423.     X 
  424.     X   SEE ALSO
  425.     X    termcap(3) 
  426.     X 
  427.     X   DIAGNOSTICS
  428.     X    If the screen doesn't clear, it didn't work. 
  429.     X 
  430.     X   AUTHOR
  431.     X     George W. Sherouse
  432.     X     30 March 1984
  433.     X 
  434.     X ---------------------------------------------------------------------------
  435.     X*/
  436.     X
  437.     X{
  438.     X    static called = 0;
  439.     X    static char id[] = "ce", page_str[10];
  440.     X    static char *point = page_str, **point2 = &point;
  441.     X    extern char bp[1024];
  442.     X    int tgetent(), tputs();
  443.     X    int putchar();
  444.     X
  445.     X    if (!called)
  446.     X    {
  447.     X    tgetstr(id, point2);
  448.     X    called++;
  449.     X    }
  450.     X
  451.     X    (void) tputs(page_str, 1, putchar);
  452.     X    return;
  453.     X}
  454. SHAR_AND_ENJOY
  455. if test 832 -ne "`wc -c < 'ClearEOL.c'`"
  456. then
  457.     echo shar: error transmitting "'ClearEOL.c'" '(should have been 832 characters)'
  458. fi
  459. fi # end of overwriting check
  460. echo shar: extracting "'GetBool.c'" '(1495 characters)'
  461. if test -f 'GetBool.c'
  462. then
  463.     echo shar: will not over-write existing file "'GetBool.c'"
  464. else
  465. sed 's/^    X//' << \SHAR_AND_ENJOY > 'GetBool.c'
  466.     X#include <stdio.h>
  467.     X#include <ctype.h>
  468.     X
  469.     Xint GetBool(Default)
  470.     Xint Default;
  471.     X
  472.     X/*
  473.     X ---------------------------------------------------------------------------
  474.     X 
  475.     X   Last revision - 
  476.     X    16 November 1984 - GWS
  477.     X    Ignore XON, XOFF
  478.     X
  479.     X     11 April 1984 - GWS
  480.     X 
  481.     X 
  482.     X   NAME
  483.     X     GetBool - "crash-proof" routine for terminal input of boolean
  484.     X 
  485.     X   SYNOPSIS
  486.     X    int GetHospNum(Default)
  487.     X    int Default;
  488.     X 
  489.     X   DESCRIPTION
  490.     X    This routine prompts and nudges the user through entry of a
  491.     X    boolean value.
  492.     X 
  493.     X   SEE ALSO
  494.     X 
  495.     X 
  496.     X   DIAGNOSTICS
  497.     X    none 
  498.     X 
  499.     X   BUGS
  500.     X    none known
  501.     X 
  502.     X   AUTHOR
  503.     X     George W. Sherouse
  504.     X     11 April 1984
  505.     X 
  506.     X ---------------------------------------------------------------------------
  507.     X*/
  508.     X
  509.     X{
  510.     X    int c;
  511.     X    char erase;
  512.     X    int val;
  513.     X    int cookie;
  514.     X
  515.     X    void underline();
  516.     X    int tgetnum();
  517.     X    char TermSetUp();
  518.     X    void TermRewind();
  519.     X
  520.     X    if ((cookie = tgetnum("ug")) < 0)
  521.     X    cookie = 0;
  522.     X
  523.     X    underline(1);
  524.     X    printf("   ");
  525.     X
  526.     X    if (cookie)
  527.     X    {
  528.     X    underline(0);
  529.     X    TermRewind(cookie);
  530.     X    }
  531.     X
  532.     X    erase = TermSetUp();    /* set no echo, single char input */
  533.     X                    /* get erase character */
  534.     X    val = Default;
  535.     X    while (1)
  536.     X    {
  537.     X        if (val)
  538.     X        printf("\b\b\byes");
  539.     X        else
  540.     X        printf("\b\b\bno ");
  541.     X
  542.     X    switch (c = (getchar() & 0177))
  543.     X    {
  544.     X    case '\015':
  545.     X        underline(0);
  546.     X        TermSetUp();
  547.     X        return(val);
  548.     X    case ' ':
  549.     X        val = !val;
  550.     X        break;
  551.     X    case 'y':
  552.     X    case 'Y':
  553.     X        val = 1;
  554.     X        break;
  555.     X    case 'n':
  556.     X    case 'N':
  557.     X        val = 0;
  558.     X        break;
  559.     X    case '\021':
  560.     X    case '\023':
  561.     X        break;
  562.     X    default:
  563.     X        printf("%c", '\007');
  564.     X    }
  565.     X    }
  566.     X}
  567. SHAR_AND_ENJOY
  568. if test 1495 -ne "`wc -c < 'GetBool.c'`"
  569. then
  570.     echo shar: error transmitting "'GetBool.c'" '(should have been 1495 characters)'
  571. fi
  572. fi # end of overwriting check
  573. echo shar: extracting "'GetFloat.c'" '(4407 characters)'
  574. if test -f 'GetFloat.c'
  575. then
  576.     echo shar: will not over-write existing file "'GetFloat.c'"
  577. else
  578. sed 's/^    X//' << \SHAR_AND_ENJOY > 'GetFloat.c'
  579.     X#include <stdio.h>
  580.     X#include <ctype.h>
  581.     X
  582.     Xfloat GetFloat(Default, field_width, places)
  583.     Xfloat Default;
  584.     Xint field_width, places;
  585.     X
  586.     X/*
  587.     X ---------------------------------------------------------------------------
  588.     X 
  589.     X   Last revision - 
  590.     X    16 November 1984 - GWS
  591.     X    Ignore XON, XOFF
  592.     X
  593.     X     11 April 1984 - GWS
  594.     X 
  595.     X 
  596.     X   NAME
  597.     X     GetFloat - "crash-proof" float from keyboard routine
  598.     X 
  599.     X   SYNOPSIS
  600.     X    float GetFloat(Default, field_width, places)
  601.     X    float Default;
  602.     X    int field_width, places;
  603.     X
  604.     X   DESCRIPTION
  605.     X    On a good day this routine will get a real value from the
  606.     X    keyboard and return it safely.  The terminal is placed in raw
  607.     X    mode and most non-digit values are beeped at and discarded.  Entry
  608.     X    is terminated by filling the field or by CR.  CR as first character
  609.     X    assumes Default.  ^X restarts.
  610.     X 
  611.     X   SEE ALSO
  612.     X 
  613.     X 
  614.     X   DIAGNOSTICS
  615.     X    none - cannot fail :-) 
  616.     X 
  617.     X   BUGS
  618.     X    Doesn't check for silly things like Default too big to fit in
  619.     X    field_width, etc.  Watch out for that minus sign!!
  620.     X    
  621.     X    Exponential notation is not supported.
  622.     X
  623.     X    This version does not let you erase over the decimal point if
  624.     X    the integer part of the field is already full.  This is not a
  625.     X    terrible hardship because you are free to ^X and start over,
  626.     X    but it really should be fixed.
  627.     X 
  628.     X   AUTHOR
  629.     X     George W. Sherouse
  630.     X     9 April 1984
  631.     X 
  632.     X ---------------------------------------------------------------------------
  633.     X*/
  634.     X
  635.     X{
  636.     X    int c;
  637.     X    float val;
  638.     X    int loop;
  639.     X    char line_buff[20];
  640.     X    char Format[80];
  641.     X    char erase, pad;
  642.     X    int point, frac_count;
  643.     X    int count;
  644.     X    int cookie;
  645.     X    int int_part;
  646.     X
  647.     X    void underline();
  648.     X    void f_clean_up();
  649.     X    char TermSetUp();
  650.     X    int tgetnum();
  651.     X    void TermRewind();
  652.     X
  653.     X    pad = ' ';
  654.     X    point = 0;
  655.     X    frac_count = 0 ;
  656.     X    if ((cookie = tgetnum("ug")) < 0)
  657.     X        cookie = 0;
  658.     X
  659.     X    underline(1);
  660.     X
  661.     X    for (loop = 0; loop < field_width; loop++)
  662.     X        printf(" ");
  663.     X    if (cookie)
  664.     X    {
  665.     X        underline(0);
  666.     X        TermRewind(cookie);
  667.     X    }
  668.     X    TermRewind(field_width);
  669.     X
  670.     X    sprintf(Format, "%%%d.%df", field_width, places);
  671.     X    printf(Format, Default);
  672.     X    TermRewind(field_width);
  673.     X    for (loop = 0; loop <= field_width; loop++)
  674.     X        line_buff[loop] = 0;
  675.     X
  676.     X    erase = TermSetUp();    /* set no echo, single char input */
  677.     X                /* get erase character */
  678.     X    count = 0;
  679.     X    int_part = field_width - places - 1;
  680.     X    while (1)
  681.     X    {
  682.     X        if (!point && count == int_part)
  683.     X        {
  684.     X        printf(".");
  685.     X        line_buff[count++] = '.';
  686.     X        point++;
  687.     X        continue;
  688.     X        }
  689.     X
  690.     X        switch (c = (getchar() & 0177))
  691.     X        {
  692.     X        case '\015':
  693.     X        if (count && line_buff[count - 1] != '-')
  694.     X        {
  695.     X            sscanf(line_buff, "%f", &val);
  696.     X            f_clean_up(count, field_width, Format, val);
  697.     X            return(val);
  698.     X        }
  699.     X        else
  700.     X        {
  701.     X            f_clean_up(count, field_width, Format, Default);
  702.     X            return(Default);
  703.     X        }
  704.     X        break;
  705.     X        case 030:
  706.     X        TermRewind(count);
  707.     X        for (loop = 0; loop < field_width; loop++)
  708.     X            line_buff[loop] = 0;
  709.     X        count = frac_count = point = 0;
  710.     X        printf(Format, Default);
  711.     X        TermRewind(field_width);
  712.     X        break;
  713.     X        case '.':
  714.     X        if (!point)
  715.     X        {
  716.     X            if (!count)
  717.     X            {
  718.     X            for (loop = 0; loop < field_width; loop++)
  719.     X                printf("%c", pad);
  720.     X            TermRewind(field_width);
  721.     X            for (loop = 0; loop < field_width; loop++)
  722.     X                line_buff[loop] = 0;
  723.     X            }
  724.     X            printf(".");
  725.     X            line_buff[count++] = '.';
  726.     X            point++;
  727.     X            break;
  728.     X        }
  729.     X        case '\021':
  730.     X        case '\023':
  731.     X        break;
  732.     X        default:
  733.     X        if (c == erase && count)
  734.     X        {
  735.     X            printf("\b%c\b", pad);
  736.     X            if (point)
  737.     X            {
  738.     X            if (frac_count)
  739.     X                frac_count--;
  740.     X            else
  741.     X                point--;
  742.     X            }
  743.     X            line_buff[--count] = 0;
  744.     X            break;
  745.     X        }
  746.     X
  747.     X        if (!count && c == '-')
  748.     X        {
  749.     X            for (loop = 0; loop < field_width; loop++)
  750.     X            printf("%c", pad);
  751.     X            TermRewind(field_width);
  752.     X            for (loop = 0; loop < field_width; loop++)
  753.     X                line_buff[loop] = 0;
  754.     X
  755.     X            line_buff[count++] = (char) c;
  756.     X            printf("-");
  757.     X            break;
  758.     X        }
  759.     X
  760.     X        if (isdigit(c) && count < field_width && frac_count < places)
  761.     X        {
  762.     X            if (!count)
  763.     X            {
  764.     X            for (loop = 0; loop < field_width; loop++)
  765.     X                printf("%c", pad);
  766.     X            TermRewind(field_width);
  767.     X            for (loop = 0; loop < field_width; loop++)
  768.     X                line_buff[loop] = 0;
  769.     X            }
  770.     X            printf("%c", c);
  771.     X            line_buff[count++] = (char) c;
  772.     X            if (point)
  773.     X            frac_count++;
  774.     X        }
  775.     X        else
  776.     X            printf("%c", '\007');
  777.     X        }
  778.     X    }
  779.     X}
  780.     X
  781.     Xvoid f_clean_up(count, field_width, Format, val)
  782.     Xint count, field_width;
  783.     Xchar *Format;
  784.     Xfloat val;
  785.     X
  786.     X{
  787.     X    int loop;
  788.     X    void underline();
  789.     X    char TermSetUp();
  790.     X    void TermRewind();
  791.     X
  792.     X    TermRewind(count);
  793.     X    printf(Format, val);
  794.     X
  795.     X    underline(0);
  796.     X    (void) TermSetUp();
  797.     X}
  798. SHAR_AND_ENJOY
  799. if test 4407 -ne "`wc -c < 'GetFloat.c'`"
  800. then
  801.     echo shar: error transmitting "'GetFloat.c'" '(should have been 4407 characters)'
  802. fi
  803. fi # end of overwriting check
  804. echo shar: extracting "'GetHospNum.c'" '(2127 characters)'
  805. if test -f 'GetHospNum.c'
  806. then
  807.     echo shar: will not over-write existing file "'GetHospNum.c'"
  808. else
  809. sed 's/^    X//' << \SHAR_AND_ENJOY > 'GetHospNum.c'
  810.     X#include <stdio.h>
  811.     X#include <ctype.h>
  812.     X
  813.     Xvoid GetHospNum(HospNum)
  814.     Xchar *HospNum;
  815.     X
  816.     X/*
  817.     X ---------------------------------------------------------------------------
  818.     X 
  819.     X   Last revision - 
  820.     X    16 November 1984 - GWS
  821.     X    Ignore XON, XOFF
  822.     X
  823.     X     11 April 1984 - GWS
  824.     X 
  825.     X 
  826.     X   NAME
  827.     X     GetHospNum - "crash-proof" routine for terminal input of ##-##-##
  828.     X 
  829.     X   SYNOPSIS
  830.     X    void GetHospNum(HospNum)
  831.     X    char *HospNum;
  832.     X 
  833.     X   DESCRIPTION
  834.     X    This routine prompts and nudges the user through entry of a
  835.     X    hospital number in the proper format.
  836.     X 
  837.     X   SEE ALSO
  838.     X 
  839.     X 
  840.     X   DIAGNOSTICS
  841.     X    none 
  842.     X 
  843.     X   BUGS
  844.     X    Doesn't do any validity checking on the number, only the format. 
  845.     X 
  846.     X   AUTHOR
  847.     X     George W. Sherouse
  848.     X     9 April 1984
  849.     X 
  850.     X ---------------------------------------------------------------------------
  851.     X*/
  852.     X
  853.     X{
  854.     X    int c;
  855.     X    char erase;
  856.     X    int count;
  857.     X    int cookie;
  858.     X
  859.     X    void underline();
  860.     X    int tgetnum();
  861.     X    char TermSetUp();
  862.     X    void TermRewind();
  863.     X
  864.     X    if ((cookie = tgetnum("ug")) < 0)
  865.     X    cookie = 0;
  866.     X
  867.     X    underline(1);
  868.     X
  869.     X    printf("  -  -  ");
  870.     X    if (cookie)
  871.     X    {
  872.     X    underline(0);
  873.     X    TermRewind(cookie);
  874.     X    }
  875.     X    TermRewind(8);
  876.     X
  877.     X    erase = TermSetUp();    /* set no echo, single char input */
  878.     X                    /* get erase character */
  879.     X    count = 0;
  880.     X    while (1)
  881.     X    {
  882.     X    switch (count)
  883.     X    {
  884.     X    case 2:
  885.     X    case 5:
  886.     X        printf("-");
  887.     X        HospNum[count++] = '-';
  888.     X        break;
  889.     X    default:
  890.     X        switch (c = (getchar() & 0177))
  891.     X        {
  892.     X        case '\015':
  893.     X        if (count == 8)
  894.     X        {
  895.     X            HospNum[8] = (char) 0;
  896.     X            underline(0);
  897.     X            TermSetUp();
  898.     X            return;
  899.     X        }
  900.     X        else
  901.     X        {
  902.     X            printf("%c", '\007');
  903.     X            break;
  904.     X        }
  905.     X        case 030:
  906.     X        TermRewind(count);
  907.     X        printf("  -  -  ");
  908.     X        count = 0;
  909.     X        TermRewind(8);
  910.     X        break;
  911.     X        case '\021':
  912.     X        case '\023':
  913.     X        break;
  914.     X        default:
  915.     X        if (c == erase && count)
  916.     X        {
  917.     X            switch (count)
  918.     X            {
  919.     X            case 3:
  920.     X            case 6:
  921.     X            printf("\b");
  922.     X            count--;
  923.     X            case 1:
  924.     X            case 2:
  925.     X            case 4:
  926.     X            case 5:
  927.     X            case 7:
  928.     X            case 8:
  929.     X            printf("\b \b");
  930.     X            HospNum[--count] = 0;
  931.     X            break;
  932.     X            }
  933.     X            break;
  934.     X        }
  935.     X
  936.     X        if (isdigit(c) && count < 8)
  937.     X        {
  938.     X            printf("%c", c);
  939.     X            HospNum[count++] = (char) c;
  940.     X        }
  941.     X        else
  942.     X            printf("%c", '\007');
  943.     X        }
  944.     X    }
  945.     X    }
  946.     X}
  947. SHAR_AND_ENJOY
  948. if test 2127 -ne "`wc -c < 'GetHospNum.c'`"
  949. then
  950.     echo shar: error transmitting "'GetHospNum.c'" '(should have been 2127 characters)'
  951. fi
  952. fi # end of overwriting check
  953. echo shar: extracting "'GetInt.c'" '(3374 characters)'
  954. if test -f 'GetInt.c'
  955. then
  956.     echo shar: will not over-write existing file "'GetInt.c'"
  957. else
  958. sed 's/^    X//' << \SHAR_AND_ENJOY > 'GetInt.c'
  959.     X#include <stdio.h>
  960.     X#include <ctype.h>
  961.     X
  962.     Xint GetInt(Default, field_width)
  963.     Xint Default, field_width;
  964.     X
  965.     X/*
  966.     X ---------------------------------------------------------------------------
  967.     X 
  968.     X   Last revision - 
  969.     X    16 November 1984 - GWS
  970.     X    Ignore XON, XOFF
  971.     X
  972.     X     11 April 1984 - GWS
  973.     X 
  974.     X 
  975.     X   NAME
  976.     X     GetInt - "crash-proof" integer from keyboard routine
  977.     X 
  978.     X   SYNOPSIS
  979.     X    int GetInt(Default, field_width)
  980.     X    int Default, field_width;
  981.     X 
  982.     X   DESCRIPTION
  983.     X    On a good day this routine will get an integer value from the
  984.     X    keyboard and return it safely.  The terminal is placed in raw
  985.     X    mode and most non-digit values are beeped at and discarded.  Entry
  986.     X    is terminated by filling the field or by CR.  CR as first character
  987.     X    assumes Default.  ^X restarts.
  988.     X 
  989.     X   SEE ALSO
  990.     X    TermSetUp, TermRewind 
  991.     X 
  992.     X   DIAGNOSTICS
  993.     X    none - cannot fail :-) 
  994.     X 
  995.     X   BUGS
  996.     X    Doesn't check for silly things like Default too big to fit in
  997.     X    field_width, etc.  Let's be particularly careful out there.
  998.     X 
  999.     X   AUTHOR
  1000.     X     George W. Sherouse
  1001.     X     6 April 1984
  1002.     X 
  1003.     X ---------------------------------------------------------------------------
  1004.     X*/
  1005.     X
  1006.     X{
  1007.     X    int c, val;
  1008.     X    int loop;
  1009.     X    char line_buff[20];
  1010.     X    char Format[80];
  1011.     X    char erase, pad;
  1012.     X    int count;
  1013.     X    int cookie;
  1014.     X
  1015.     X    void underline();
  1016.     X    void clean_up();
  1017.     X    int tgetnum();
  1018.     X    char TermSetUp();
  1019.     X    void TermRewind();
  1020.     X
  1021.     X    pad = ' ';
  1022.     X    if ((cookie = tgetnum("ug")) < 0)
  1023.     X        cookie = 0;
  1024.     X
  1025.     X    underline(1);
  1026.     X
  1027.     X    for (loop = 0; loop < field_width; loop++)
  1028.     X        printf(" ");
  1029.     X    if (cookie)
  1030.     X    {
  1031.     X        underline(0);
  1032.     X        TermRewind(cookie);
  1033.     X    }
  1034.     X    TermRewind(field_width);
  1035.     X
  1036.     X    sprintf(Format, "%%%dd", field_width);
  1037.     X    printf(Format, Default);
  1038.     X    TermRewind(field_width);
  1039.     X    for (loop = 0; loop <= field_width; loop++)
  1040.     X        line_buff[loop] = 0;
  1041.     X
  1042.     X    erase = TermSetUp();    /* set no echo, single char input */
  1043.     X                /* get erase character */
  1044.     X    count = 0;
  1045.     X    while (1)
  1046.     X    {
  1047.     X        switch (c = (getchar() & 0177))
  1048.     X        {
  1049.     X        case '\015':
  1050.     X        if (count && line_buff[count - 1] != '-')
  1051.     X        {
  1052.     X            sscanf(line_buff, "%d", &val);
  1053.     X            clean_up(count, field_width, Format, val);
  1054.     X            return(val);
  1055.     X        }
  1056.     X        else
  1057.     X        {
  1058.     X            clean_up(count, field_width, Format, Default);
  1059.     X            return(Default);
  1060.     X        }
  1061.     X        break;
  1062.     X        case 030:
  1063.     X        TermRewind(count);
  1064.     X        for (loop = 0; loop < field_width; loop++)
  1065.     X            line_buff[loop] = 0;
  1066.     X        count = 0;
  1067.     X        printf(Format, Default);
  1068.     X        TermRewind(field_width);
  1069.     X        break;
  1070.     X        case '\021':
  1071.     X        case '\023':
  1072.     X        break;
  1073.     X        default:
  1074.     X        if (c == erase && count)
  1075.     X        {
  1076.     X            printf("\b%c\b", pad);
  1077.     X            line_buff[--count] = 0;
  1078.     X            break;
  1079.     X        }
  1080.     X
  1081.     X        if (!count && c == '-')
  1082.     X        {
  1083.     X            for (loop = 0; loop < field_width; loop++)
  1084.     X            printf("%c", pad);
  1085.     X            TermRewind(field_width);
  1086.     X            for (loop = 0; loop < field_width; loop++)
  1087.     X                line_buff[loop] = 0;
  1088.     X
  1089.     X            line_buff[count++] = (char) c;
  1090.     X            printf("-");
  1091.     X            break;
  1092.     X        }
  1093.     X
  1094.     X        if (isdigit(c) && count < field_width)
  1095.     X        {
  1096.     X            if (!count)
  1097.     X            {
  1098.     X            for (loop = 0; loop < field_width; loop++)
  1099.     X                printf("%c", pad);
  1100.     X            TermRewind(field_width);
  1101.     X            for (loop = 0; loop < field_width; loop++)
  1102.     X                line_buff[loop] = 0;
  1103.     X            }
  1104.     X            printf("%c", c);
  1105.     X            line_buff[count++] = (char) c;
  1106.     X        }
  1107.     X        else
  1108.     X            printf("%c", '\007');
  1109.     X        }
  1110.     X    }
  1111.     X}
  1112.     X
  1113.     Xvoid clean_up(count, field_width, Format, val)
  1114.     Xint count, field_width;
  1115.     Xchar *Format;
  1116.     Xint val;
  1117.     X
  1118.     X{
  1119.     X    int loop;
  1120.     X    void underline();
  1121.     X    char TermSetUp();
  1122.     X    void TermRewind();
  1123.     X
  1124.     X    TermRewind(count);
  1125.     X    printf(Format, val);
  1126.     X
  1127.     X    underline(0);
  1128.     X    (void) TermSetUp();
  1129.     X}
  1130. SHAR_AND_ENJOY
  1131. if test 3374 -ne "`wc -c < 'GetInt.c'`"
  1132. then
  1133.     echo shar: error transmitting "'GetInt.c'" '(should have been 3374 characters)'
  1134. fi
  1135. fi # end of overwriting check
  1136. echo shar: extracting "'GetString.c'" '(2149 characters)'
  1137. if test -f 'GetString.c'
  1138. then
  1139.     echo shar: will not over-write existing file "'GetString.c'"
  1140. else
  1141. sed 's/^    X//' << \SHAR_AND_ENJOY > 'GetString.c'
  1142.     X#include <stdio.h>
  1143.     X#include <ctype.h>
  1144.     X
  1145.     Xvoid GetString(string, size, nullOK)
  1146.     Xchar *string;
  1147.     Xint size;
  1148.     Xint nullOK;
  1149.     X
  1150.     X/*
  1151.     X ---------------------------------------------------------------------------
  1152.     X 
  1153.     X   Last revision - 
  1154.     X    16 November 1984 - GWS
  1155.     X    Ignore XON, XOFF
  1156.     X
  1157.     X     11 April 1984 - GWS
  1158.     X 
  1159.     X 
  1160.     X   NAME
  1161.     X     GetString - "crash-proof" routine for terminal input of string
  1162.     X 
  1163.     X   SYNOPSIS
  1164.     X    void GetString(string, size, nullOK)
  1165.     X    char *string;
  1166.     X    int size;
  1167.     X    int nullOK;
  1168.     X 
  1169.     X   DESCRIPTION
  1170.     X    This routine prompts and nudges the user through entry of a
  1171.     X    character string.  'Size' is the number of characters in'string'.
  1172.     X    'String' should therefore be dimensioned to size + 1.
  1173.     X    'NullOK' is a boolean that tells us whether a null string is
  1174.     X    acceptable.
  1175.     X 
  1176.     X   SEE ALSO
  1177.     X 
  1178.     X 
  1179.     X   DIAGNOSTICS
  1180.     X    none 
  1181.     X 
  1182.     X   BUGS
  1183.     X    none known
  1184.     X 
  1185.     X   AUTHOR
  1186.     X     George W. Sherouse
  1187.     X     11 April 1984
  1188.     X 
  1189.     X ---------------------------------------------------------------------------
  1190.     X*/
  1191.     X
  1192.     X{
  1193.     X    int c;
  1194.     X    char erase;
  1195.     X    int loop;
  1196.     X    int cookie;
  1197.     X    int count;
  1198.     X
  1199.     X    void underline();
  1200.     X    int tgetnum();
  1201.     X    char TermSetUp();
  1202.     X    void TermRewind();
  1203.     X
  1204.     X    if ((cookie = tgetnum("ug")) < 0)
  1205.     X    cookie = 0;
  1206.     X
  1207.     X    underline(1);
  1208.     X    for (loop = 0; loop < size; loop++)
  1209.     X    {
  1210.     X    printf(" ");
  1211.     X    string[loop] = (char) 0;
  1212.     X    }
  1213.     X    string[size] = (char) 0;
  1214.     X
  1215.     X    if (cookie)
  1216.     X    {
  1217.     X    underline(0);
  1218.     X    TermRewind(cookie);
  1219.     X    }
  1220.     X    TermRewind(size);
  1221.     X
  1222.     X    erase = TermSetUp();    /* set no echo, single char input */
  1223.     X                    /* get erase character */
  1224.     X
  1225.     X    count = 0;
  1226.     X    while (1)
  1227.     X    {
  1228.     X    switch (c = (getchar() & 0177))
  1229.     X    {
  1230.     X    case '\015':
  1231.     X        if (count || nullOK)
  1232.     X        {
  1233.     X        for (loop = count; loop < size; loop++)
  1234.     X            printf(" ");
  1235.     X        underline(0);
  1236.     X        (void) TermSetUp();
  1237.     X        return;
  1238.     X        }
  1239.     X        else
  1240.     X        {
  1241.     X        printf("%c", '\007');
  1242.     X        break;
  1243.     X        }
  1244.     X    case '\030':
  1245.     X        while (count)
  1246.     X        {
  1247.     X        string[--count] = (char) 0;
  1248.     X        printf("\b \b");
  1249.     X        }
  1250.     X        break;
  1251.     X    case '\021':
  1252.     X    case '\023':
  1253.     X        break;
  1254.     X    default:
  1255.     X        if (count && c == erase)
  1256.     X        {
  1257.     X        printf("\b \b");
  1258.     X        string[--count] = (char) 0;
  1259.     X        break;
  1260.     X        }
  1261.     X
  1262.     X        if (isprint(c) && count < size)
  1263.     X        {
  1264.     X        printf("%c", c);
  1265.     X        string[count++] = c;
  1266.     X        break;
  1267.     X        }
  1268.     X
  1269.     X        printf("%c", '\007');
  1270.     X    }
  1271.     X    }
  1272.     X}
  1273. SHAR_AND_ENJOY
  1274. if test 2149 -ne "`wc -c < 'GetString.c'`"
  1275. then
  1276.     echo shar: error transmitting "'GetString.c'" '(should have been 2149 characters)'
  1277. fi
  1278. fi # end of overwriting check
  1279. echo shar: extracting "'InitTerm.c'" '(1074 characters)'
  1280. if test -f 'InitTerm.c'
  1281. then
  1282.     echo shar: will not over-write existing file "'InitTerm.c'"
  1283. else
  1284. sed 's/^    X//' << \SHAR_AND_ENJOY > 'InitTerm.c'
  1285.     X#include <stdio.h>
  1286.     X
  1287.     Xchar bp[1024];
  1288.     X
  1289.     Xint InitTerm()
  1290.     X
  1291.     X/*
  1292.     X ---------------------------------------------------------------------------
  1293.     X 
  1294.     X   Last revision - 
  1295.     X     30 March 1984 - GWS
  1296.     X 
  1297.     X 
  1298.     X   NAME
  1299.     X     InitTerm - initialize data area for screen handling routines
  1300.     X 
  1301.     X   SYNOPSIS
  1302.     X    InitTerm() 
  1303.     X 
  1304.     X   DESCRIPTION
  1305.     X    Calls getenv to find out what terminal type to use and
  1306.     X    then calls tgetent to initialize the string containing
  1307.     X    the termcap.
  1308.     X 
  1309.     X   SEE ALSO
  1310.     X    termcap(3x), page, gotoxy, underline, stand_out, clear_eol 
  1311.     X 
  1312.     X   DIAGNOSTICS
  1313.     X    Returns 0 if successful
  1314.     X           -1 if getenv fails
  1315.     X           -2 if tgetent cannot open termcap file
  1316.     X           -3 if tgetent cannot find entry for terminal
  1317.     X 
  1318.     X   BUGS
  1319.     X    none known 
  1320.     X 
  1321.     X   AUTHOR
  1322.     X     George W. Sherouse
  1323.     X     30 March 1984
  1324.     X 
  1325.     X ---------------------------------------------------------------------------
  1326.     X*/
  1327.     X
  1328.     X
  1329.     X{
  1330.     X    int tgetent(), ret;
  1331.     X    char *getenv(), *cret;
  1332.     X
  1333.     X    cret = getenv("TERM");
  1334.     X    if (cret == NULL)
  1335.     X    return(-1);
  1336.     X
  1337.     X    ret = tgetent(bp, cret);
  1338.     X    switch (ret)
  1339.     X    {
  1340.     X    case -1:
  1341.     X    return(-2);
  1342.     X    case 0:
  1343.     X    return(-3);
  1344.     X    case 1:
  1345.     X    return(0);
  1346.     X    }
  1347.     X}
  1348. SHAR_AND_ENJOY
  1349. if test 1074 -ne "`wc -c < 'InitTerm.c'`"
  1350. then
  1351.     echo shar: error transmitting "'InitTerm.c'" '(should have been 1074 characters)'
  1352. fi
  1353. fi # end of overwriting check
  1354. echo shar: extracting "'MenuPick.c'" '(4175 characters)'
  1355. if test -f 'MenuPick.c'
  1356. then
  1357.     echo shar: will not over-write existing file "'MenuPick.c'"
  1358. else
  1359. sed 's/^    X//' << \SHAR_AND_ENJOY > 'MenuPick.c'
  1360.     X#include <stdio.h>
  1361.     X#include <ctype.h>
  1362.     X#include <strings.h>
  1363.     X#include "term.h"
  1364.     X
  1365.     X#define TRUE 1
  1366.     X#define FALSE 0
  1367.     X#define BASE 3
  1368.     X
  1369.     Xint MenuPick(Prompt, ChoiceList, ChoiceCount)
  1370.     Xchar *Prompt;
  1371.     Xchar **ChoiceList;
  1372.     Xint ChoiceCount;
  1373.     X
  1374.     X/*
  1375.     X ---------------------------------------------------------------------------
  1376.     X 
  1377.     X   Last revision - 
  1378.     X     23 October 1984 - GWS
  1379.     X 
  1380.     X 
  1381.     X   NAME
  1382.     X     MenuPick - "crash-proof" routine for picking one of a list of strings
  1383.     X 
  1384.     X   SYNOPSIS
  1385.     X    int MenuPick(Prompt, ChoiceList, ChoiceCount)
  1386.     X    char *Prompt;
  1387.     X    char **ChoiceList;
  1388.     X    int ChoiceCount;
  1389.     X 
  1390.     X   DESCRIPTION
  1391.     X    This routine prompts and nudges the user through selection of a
  1392.     X    string from a table of strings - useful for choosing an item
  1393.     X    from a menu for instance.  The options are displayed in a menu
  1394.     X    format with one at a time highlighted.  The current item is
  1395.     X    selected by pressing RETURN.  The space bar advances, the 
  1396.     X    up-arrow backs up.  The return value of the function is the
  1397.     X    index of the chosen string (0 indexed).
  1398.     X 
  1399.     X   SEE ALSO
  1400.     X 
  1401.     X 
  1402.     X   DIAGNOSTICS
  1403.     X    none 
  1404.     X 
  1405.     X   BUGS
  1406.     X    none known
  1407.     X 
  1408.     X   AUTHOR
  1409.     X     George W. Sherouse
  1410.     X     22 October 1984
  1411.     X 
  1412.     X ---------------------------------------------------------------------------
  1413.     X*/
  1414.     X
  1415.     X{
  1416.     X    int    c,
  1417.     X        start,
  1418.     X        stop,
  1419.     X        select;
  1420.     X
  1421.     X/*
  1422.     XIn the silly case where there is only one choice, just return the index 0.
  1423.     X*/
  1424.     X    if (ChoiceCount == 1)
  1425.     X    return(0);
  1426.     X
  1427.     X    select = 0;
  1428.     X    paint_screen(Prompt, ChoiceList, ChoiceCount, &start, &stop, select, TRUE);
  1429.     X    while (1)
  1430.     X    {
  1431.     X    switch (c = (getchar() & 0x7f))
  1432.     X    {
  1433.     X    case '\015':
  1434.     X        TermSetUp();
  1435.     X        return(select);
  1436.     X    case ' ':
  1437.     X        if (++select == ChoiceCount)
  1438.     X        select = 0;
  1439.     X        paint_screen(Prompt, ChoiceList, ChoiceCount, &start, &stop,
  1440.     X            select, FALSE);
  1441.     X        break;
  1442.     X    case '^':
  1443.     X        if (--select < 0)
  1444.     X        select = ChoiceCount - 1;
  1445.     X        paint_screen(Prompt, ChoiceList, ChoiceCount, &start, &stop,
  1446.     X            select, FALSE);
  1447.     X        break;
  1448.     X    case '>':
  1449.     X        select = stop + 1;
  1450.     X        if (select == ChoiceCount)
  1451.     X        select = 0;
  1452.     X        paint_screen(Prompt, ChoiceList, ChoiceCount, &start, &stop,
  1453.     X            select, FALSE);
  1454.     X        break;
  1455.     X    case '\021':
  1456.     X    case '\023':
  1457.     X        break;
  1458.     X    default:
  1459.     X        printf("%c", '\007');
  1460.     X    }
  1461.     X    }
  1462.     X}
  1463.     X
  1464.     Xpaint_screen(Prompt, ChoiceList, ChoiceCount, start, stop, select, first)
  1465.     Xchar *Prompt;
  1466.     Xchar **ChoiceList;
  1467.     Xint ChoiceCount;
  1468.     Xint *start;
  1469.     Xint *stop;
  1470.     Xint select;
  1471.     Xint first;
  1472.     X
  1473.     X{
  1474.     X    int        tgetnum();
  1475.     X
  1476.     X    static int    too_many = FALSE,
  1477.     X        current,
  1478.     X        previous,
  1479.     X        old_start,
  1480.     X        cookie;
  1481.     X
  1482.     X    int        loop,
  1483.     X        loop1,
  1484.     X        line,
  1485.     X        temp;
  1486.     X
  1487.     X    char    erase;
  1488.     X
  1489.     X    if (first)
  1490.     X    {
  1491.     X
  1492.     X/*
  1493.     XFind out if we need to cope with magic cookies.
  1494.     X*/
  1495.     X    if ((cookie = tgetnum("ug")) < 0)
  1496.     X        cookie = 0;
  1497.     X
  1498.     X    if (ChoiceCount > 15)
  1499.     X        too_many = TRUE;
  1500.     X
  1501.     X    current = old_start = -1;
  1502.     X    previous = *start = 0;
  1503.     X    if (too_many)
  1504.     X        *stop = 14;
  1505.     X    else
  1506.     X        *stop = ChoiceCount - 1;
  1507.     X
  1508.     X    erase = TermSetUp();    /* set no echo, single char input */
  1509.     X                    /* get erase character */
  1510.     X
  1511.     X    first = FALSE;
  1512.     X    }
  1513.     X    else
  1514.     X    {
  1515.     X    if (select < *start)
  1516.     X        *start -= 15;
  1517.     X    if (select > *stop)
  1518.     X        *start += 15;
  1519.     X    if (*start >= ChoiceCount)
  1520.     X        *start = 0;
  1521.     X    if (*start < 0)
  1522.     X        *start = ((ChoiceCount - 1) / 15) * 15;
  1523.     X
  1524.     X    *stop = *start + 14;
  1525.     X    if (*stop >= ChoiceCount)
  1526.     X        *stop = ChoiceCount - 1;
  1527.     X    }
  1528.     X
  1529.     X/*
  1530.     XClear the stage for the action
  1531.     X*/
  1532.     X    if (*start == old_start)
  1533.     X    {
  1534.     X    gotoxy(1, BASE + previous);
  1535.     X    ClearEOL();
  1536.     X    gotoxy(1, BASE + previous);
  1537.     X    for (loop = 0; loop < cookie; loop++)
  1538.     X        printf(" ");
  1539.     X    printf("%s", ChoiceList[*start + previous]);
  1540.     X
  1541.     X    current = select - *start;
  1542.     X    gotoxy(1, BASE + current);
  1543.     X    ClearEOL();
  1544.     X    gotoxy(1, BASE + current);
  1545.     X    underline(TRUE);
  1546.     X    printf("%s", ChoiceList[*start + current]);
  1547.     X    underline(FALSE);
  1548.     X
  1549.     X    previous = current;
  1550.     X    }
  1551.     X    else
  1552.     X    {
  1553.     X    page();
  1554.     X    center(1, Prompt, 1);
  1555.     X    line = BASE;
  1556.     X
  1557.     X    for (loop = *start; loop <= *stop; loop++)
  1558.     X    {
  1559.     X        gotoxy(1, line++);
  1560.     X        if (loop == select)
  1561.     X        {
  1562.     X        underline(TRUE);
  1563.     X        printf("%s", ChoiceList[loop]);
  1564.     X        underline(FALSE);
  1565.     X        }
  1566.     X        else
  1567.     X        {
  1568.     X        for (loop1 = 0; loop1 < cookie; loop1++)
  1569.     X            printf(" ");
  1570.     X        printf("%s", ChoiceList[loop]);
  1571.     X        }
  1572.     X    }
  1573.     X    previous = select - *start;
  1574.     X    old_start = *start;
  1575.     X    }
  1576.     X
  1577.     X    gotoxy(1, 23);
  1578.     X    printf("Press RETURN to accept, SPACE to step forward, ^ to back up");
  1579.     X    if (too_many)
  1580.     X    printf(", > for next page");
  1581.     X}
  1582. SHAR_AND_ENJOY
  1583. if test 4175 -ne "`wc -c < 'MenuPick.c'`"
  1584. then
  1585.     echo shar: error transmitting "'MenuPick.c'" '(should have been 4175 characters)'
  1586. fi
  1587. fi # end of overwriting check
  1588. echo shar: extracting "'PickOne.c'" '(2497 characters)'
  1589. if test -f 'PickOne.c'
  1590. then
  1591.     echo shar: will not over-write existing file "'PickOne.c'"
  1592. else
  1593. sed 's/^    X//' << \SHAR_AND_ENJOY > 'PickOne.c'
  1594.     X#include <stdio.h>
  1595.     X#include <ctype.h>
  1596.     X#include <strings.h>
  1597.     X
  1598.     Xint PickOne(ChoiceList, ChoiceCount)
  1599.     Xchar **ChoiceList;
  1600.     Xint ChoiceCount;
  1601.     X
  1602.     X/*
  1603.     X ---------------------------------------------------------------------------
  1604.     X 
  1605.     X   Last revision - 
  1606.     X    16 November 1984 - GWS
  1607.     X    Ignore XON, XOFF
  1608.     X
  1609.     X     12 April 1984 - GWS
  1610.     X 
  1611.     X 
  1612.     X   NAME
  1613.     X     PickOne - "crash-proof" routine for picking one of a list of
  1614.     X          list of strings
  1615.     X 
  1616.     X   SYNOPSIS
  1617.     X    int PickOne(ChoiceList, ChoiceCount)
  1618.     X    char **ChoiceList;
  1619.     X    int ChoiceCount;
  1620.     X 
  1621.     X   DESCRIPTION
  1622.     X    This routine prompts and nudges the user through selection of a
  1623.     X    string from a table of strings - useful for choosing an item
  1624.     X    from a menu for instance.  The options are displayed one at a
  1625.     X    time.  The current item is selected by pressing return.  The
  1626.     X    space bar advances, the up-arrow backs up.  The return
  1627.     X    value of the function is the index of the chosen string.
  1628.     X 
  1629.     X   SEE ALSO
  1630.     X 
  1631.     X 
  1632.     X   DIAGNOSTICS
  1633.     X    none 
  1634.     X 
  1635.     X   BUGS
  1636.     X    none known
  1637.     X 
  1638.     X   AUTHOR
  1639.     X     George W. Sherouse
  1640.     X     11 April 1984
  1641.     X 
  1642.     X ---------------------------------------------------------------------------
  1643.     X*/
  1644.     X
  1645.     X{
  1646.     X    int c;
  1647.     X    char erase;
  1648.     X    int val;
  1649.     X    int cookie;
  1650.     X    int biggest;
  1651.     X    int temp;
  1652.     X    int loop;
  1653.     X    char Format[80];
  1654.     X
  1655.     X    void underline();
  1656.     X    int tgetnum();
  1657.     X    char TermSetUp();
  1658.     X    void TermRewind();
  1659.     X    int strlen();
  1660.     X
  1661.     X/*
  1662.     XIn the silly case where there is only one choice, just print it
  1663.     Xand return the index 0.
  1664.     X*/
  1665.     X    if (ChoiceCount == 1)
  1666.     X    {
  1667.     X    underline(1);
  1668.     X    printf("%s", ChoiceList[0]);
  1669.     X    underline(0);
  1670.     X    return(0);
  1671.     X    }
  1672.     X/*
  1673.     XFind the longest string in the bunch
  1674.     X*/
  1675.     X    biggest = strlen(ChoiceList[0]);
  1676.     X    for (loop = 1; loop < ChoiceCount; loop++)
  1677.     X    if ((temp = strlen(ChoiceList[loop])) > biggest)
  1678.     X        biggest = temp;
  1679.     X
  1680.     X/*
  1681.     XFind out if we need to cope with magic cookies.
  1682.     X*/
  1683.     X    if ((cookie = tgetnum("ug")) < 0)
  1684.     X    cookie = 0;
  1685.     X
  1686.     X    underline(1);
  1687.     X    for (loop = 0; loop < biggest; loop++)
  1688.     X    printf(" ");
  1689.     X
  1690.     X    if (cookie)
  1691.     X    {
  1692.     X    underline(0);
  1693.     X    TermRewind(cookie);
  1694.     X    }
  1695.     X
  1696.     X    erase = TermSetUp();    /* set no echo, single char input */
  1697.     X                    /* get erase character */
  1698.     X    sprintf(Format, "%%-%ds", biggest);
  1699.     X
  1700.     X    val = 0;
  1701.     X    while (1)
  1702.     X    {
  1703.     X    TermRewind(biggest);
  1704.     X    printf(Format, ChoiceList[val]);
  1705.     X
  1706.     X    switch (c = (getchar() & 0177))
  1707.     X    {
  1708.     X    case '\015':
  1709.     X        underline(0);
  1710.     X        TermSetUp();
  1711.     X        return(val);
  1712.     X    case ' ':
  1713.     X        if (++val == ChoiceCount)
  1714.     X        val = 0;
  1715.     X        break;
  1716.     X    case '^':
  1717.     X        if (--val < 0)
  1718.     X        val = ChoiceCount - 1;
  1719.     X        break;
  1720.     X    case '\021':
  1721.     X    case '\023':
  1722.     X        break;
  1723.     X    default:
  1724.     X        printf("%c", '\007');
  1725.     X    }
  1726.     X    }
  1727.     X}
  1728. SHAR_AND_ENJOY
  1729. if test 2497 -ne "`wc -c < 'PickOne.c'`"
  1730. then
  1731.     echo shar: error transmitting "'PickOne.c'" '(should have been 2497 characters)'
  1732. fi
  1733. fi # end of overwriting check
  1734. echo shar: extracting "'StandOut.c'" '(1086 characters)'
  1735. if test -f 'StandOut.c'
  1736. then
  1737.     echo shar: will not over-write existing file "'StandOut.c'"
  1738. else
  1739. sed 's/^    X//' << \SHAR_AND_ENJOY > 'StandOut.c'
  1740.     X
  1741.     Xvoid StandOut(on_or_off)
  1742.     Xint on_or_off;
  1743.     X
  1744.     X
  1745.     X/*
  1746.     X ---------------------------------------------------------------------------
  1747.     X 
  1748.     X   Last revision - 
  1749.     X     30 March 1984 - GWS
  1750.     X 
  1751.     X 
  1752.     X   NAME
  1753.     X     StandOut - set or clear terminal stand-out mode
  1754.     X 
  1755.     X   SYNOPSIS
  1756.     X    void StandOut(on_or_off) 
  1757.     X    int on_or_off;
  1758.     X 
  1759.     X   DESCRIPTION
  1760.     X    Uses termcap(3x) routines to set terminal mode. 
  1761.     X 
  1762.     X   SEE ALSO
  1763.     X    termcap(3) 
  1764.     X 
  1765.     X   DIAGNOSTICS
  1766.     X    If the mode doesn't change, it didn't work. 
  1767.     X 
  1768.     X   AUTHOR
  1769.     X     George W. Sherouse
  1770.     X     30 March 1984
  1771.     X 
  1772.     X ---------------------------------------------------------------------------
  1773.     X*/
  1774.     X
  1775.     X{
  1776.     X    static called = 0;
  1777.     X    static char so_id[] = "so", se_id[] = "se", so_str[10], se_str[10];
  1778.     X    static char *so_point = so_str, **so_point2 = &so_point;
  1779.     X    static char *se_point = se_str, **se_point2 = &se_point;
  1780.     X    extern char bp[1024];
  1781.     X    int tgetent(), tputs();
  1782.     X    int putchar();
  1783.     X
  1784.     X    if (!called)
  1785.     X    {
  1786.     X    tgetstr(so_id, so_point2);
  1787.     X    tgetstr(se_id, se_point2);
  1788.     X    called++;
  1789.     X    }
  1790.     X
  1791.     X    if (on_or_off)
  1792.     X        (void) tputs(so_str, 1, putchar);
  1793.     X    else
  1794.     X        (void) tputs(se_str, 1, putchar);
  1795.     X    return;
  1796.     X}
  1797. SHAR_AND_ENJOY
  1798. if test 1086 -ne "`wc -c < 'StandOut.c'`"
  1799. then
  1800.     echo shar: error transmitting "'StandOut.c'" '(should have been 1086 characters)'
  1801. fi
  1802. fi # end of overwriting check
  1803. echo shar: extracting "'TermRewind.c'" '(209 characters)'
  1804. if test -f 'TermRewind.c'
  1805. then
  1806.     echo shar: will not over-write existing file "'TermRewind.c'"
  1807. else
  1808. sed 's/^    X//' << \SHAR_AND_ENJOY > 'TermRewind.c'
  1809.     X
  1810.     X#include <stdio.h>
  1811.     X
  1812.     Xvoid TermRewind(count)
  1813.     Xint count;
  1814.     X/*
  1815.     X
  1816.     Xvoid TermRewind(count)
  1817.     Xint count;
  1818.     X
  1819.     XBacks up the cursor 'count' spaces
  1820.     X
  1821.     X*/
  1822.     X
  1823.     X{
  1824.     X    int loop;
  1825.     X
  1826.     X    for (loop = 0; loop < count; loop++)
  1827.     X    printf("\b");
  1828.     X}
  1829. SHAR_AND_ENJOY
  1830. if test 209 -ne "`wc -c < 'TermRewind.c'`"
  1831. then
  1832.     echo shar: error transmitting "'TermRewind.c'" '(should have been 209 characters)'
  1833. fi
  1834. fi # end of overwriting check
  1835. echo shar: extracting "'TermSetUp.c'" '(1713 characters)'
  1836. if test -f 'TermSetUp.c'
  1837. then
  1838.     echo shar: will not over-write existing file "'TermSetUp.c'"
  1839. else
  1840. sed 's/^    X//' << \SHAR_AND_ENJOY > 'TermSetUp.c'
  1841.     X#include <stdio.h>
  1842.     X#include <sgtty.h>
  1843.     X#include <sys/ioctl.h>
  1844.     X
  1845.     Xchar TermSetUp()
  1846.     X
  1847.     X/*
  1848.     X ---------------------------------------------------------------------------
  1849.     X 
  1850.     X   Last revision - 
  1851.     X     11 April 1984 - GWS
  1852.     X 
  1853.     X 
  1854.     X   NAME
  1855.     X     TermSetUp - set/clear terminal no echo, raw mode
  1856.     X 
  1857.     X   SYNOPSIS
  1858.     X    char TermSetUp()
  1859.     X 
  1860.     X   DESCRIPTION
  1861.     X    This routine is a toggle function which places the terminal
  1862.     X    into RAW and !ECHO modes on odd calls and back to the original
  1863.     X    state on even-number calls.  The return character is the terminal's
  1864.     X    erase character.
  1865.     X 
  1866.     X   SEE ALSO
  1867.     X 
  1868.     X 
  1869.     X   DIAGNOSTICS
  1870.     X    Will exit(1) on any error. 
  1871.     X 
  1872.     X   BUGS
  1873.     X    none known 
  1874.     X 
  1875.     X   AUTHOR
  1876.     X     George W. Sherouse
  1877.     X     9 April 1984
  1878.     X 
  1879.     X ---------------------------------------------------------------------------
  1880.     X*/
  1881.     X
  1882.     X{
  1883.     X    struct sgttyb params;
  1884.     X    int ret;
  1885.     X    static int count=0;
  1886.     X    static struct sgttyb old_params;
  1887.     X    int ioctl();
  1888.     X
  1889.     X    if (!count)
  1890.     X    {
  1891.     X    ret = ioctl(0, TIOCGETP, &old_params);
  1892.     X    if (ret == -1)
  1893.     X    {
  1894.     X        fprintf(stderr, "ioctl fail\n");
  1895.     X        perror("TermSetUp");
  1896.     X        exit(1);
  1897.     X    }
  1898.     X    ret = ioctl(0, TIOCGETP, ¶ms);
  1899.     X    if (ret == -1)
  1900.     X    {
  1901.     X        fprintf(stderr, "ioctl fail\n");
  1902.     X        perror("TermSetUp");
  1903.     X        exit(1);
  1904.     X    }
  1905.     X
  1906.     X    /* single-character activation, disable all character processing */
  1907.     X    params.sg_flags |= RAW;
  1908.     X    if (params.sg_flags & ECHO)
  1909.     X        params.sg_flags ^= ECHO;
  1910.     X    ret = ioctl(0, TIOCSETP, ¶ms);
  1911.     X    if (ret == -1)
  1912.     X    {
  1913.     X        fprintf(stderr, "ioctl fail\n");
  1914.     X        perror("TermSetUp");
  1915.     X        exit(1);
  1916.     X    }
  1917.     X    count++;
  1918.     X    }
  1919.     X    else
  1920.     X    {
  1921.     X/* put it back the way you found it */
  1922.     X    ret = ioctl(0, TIOCSETP, &old_params);
  1923.     X    if (ret == -1)
  1924.     X    {
  1925.     X        fprintf(stderr, "ioctl fail\n");
  1926.     X        perror("TermSetUp");
  1927.     X        exit(1);
  1928.     X    }
  1929.     X    count = 0;
  1930.     X    }
  1931.     X
  1932.     X    return(params.sg_erase);
  1933.     X}
  1934. SHAR_AND_ENJOY
  1935. if test 1713 -ne "`wc -c < 'TermSetUp.c'`"
  1936. then
  1937.     echo shar: error transmitting "'TermSetUp.c'" '(should have been 1713 characters)'
  1938. fi
  1939. fi # end of overwriting check
  1940. echo shar: extracting "'center.c'" '(1845 characters)'
  1941. if test -f 'center.c'
  1942. then
  1943.     echo shar: will not over-write existing file "'center.c'"
  1944. else
  1945. sed 's/^    X//' << \SHAR_AND_ENJOY > 'center.c'
  1946.     X#include <strings.h>
  1947.     X
  1948.     Xvoid center(line, string, mode)
  1949.     Xint line;
  1950.     Xchar *string;
  1951.     Xint mode;
  1952.     X
  1953.     X/*
  1954.     X ---------------------------------------------------------------------------
  1955.     X 
  1956.     X   Last revision - 
  1957.     X    17 January 1985 - GWS
  1958.     X    Change to use screen width from termcap.
  1959.     X
  1960.     X     2 April 1984 - GWS
  1961.     X 
  1962.     X 
  1963.     X   NAME
  1964.     X     center - center string in screen on specified line
  1965.     X 
  1966.     X   SYNOPSIS
  1967.     X    void center(line, string, mode)
  1968.     X    int line;
  1969.     X    char *string;
  1970.     X    int mode;
  1971.     X 
  1972.     X   DESCRIPTION
  1973.     X    This routine uses the termcap(3x) routines to center and
  1974.     X    optionally emphasize a string.  'Line' is the terminal line
  1975.     X    number on which the string is to be placed, numbered starting
  1976.     X    with 1.  'Mode' takes one of three values:
  1977.     X        0 - no control characters sent
  1978.     X        1 - underline mode turned on before and off after 'string'
  1979.     X        2 - stand-out mode turned on before and off after 'string'
  1980.     X    A call to InitTerm must be made before the first call to center.
  1981.     X 
  1982.     X   SEE ALSO
  1983.     X    termcap(3x), InitTerm, underline, StandOut 
  1984.     X 
  1985.     X   DIAGNOSTICS
  1986.     X    none 
  1987.     X 
  1988.     X   BUGS
  1989.     X    does not check for string too long to fit on one line 
  1990.     X 
  1991.     X   AUTHOR
  1992.     X     George W. Sherouse
  1993.     X     31 March 1984
  1994.     X 
  1995.     X ---------------------------------------------------------------------------
  1996.     X*/
  1997.     X
  1998.     X{
  1999.     X    int col;
  2000.     X    int cookie;
  2001.     X
  2002.     X    int strlen();
  2003.     X    void gotoxy();
  2004.     X    void underline();
  2005.     X    void StandOut();
  2006.     X
  2007.     X    col = (tgetnum("co") - strlen(string)) / 2;
  2008.     X    switch (mode)
  2009.     X    {
  2010.     X    case 0:
  2011.     X    break;
  2012.     X    case 1:
  2013.     X    cookie = tgetnum("ug");
  2014.     X    if (cookie > 0)
  2015.     X        col -= cookie;
  2016.     X    break;
  2017.     X    case 2:
  2018.     X    cookie = tgetnum("sg");
  2019.     X    if (cookie > 0)
  2020.     X        col -= cookie;
  2021.     X    break;
  2022.     X    }
  2023.     X    gotoxy(col, line);
  2024.     X    switch (mode)
  2025.     X    {
  2026.     X    case 0:
  2027.     X    break;
  2028.     X    case 1:
  2029.     X    underline(1);
  2030.     X    break;
  2031.     X    case 2:
  2032.     X    StandOut(1);
  2033.     X    break;
  2034.     X    }
  2035.     X
  2036.     X    printf(string);
  2037.     X
  2038.     X    switch (mode)
  2039.     X    {
  2040.     X    case 0:
  2041.     X    break;
  2042.     X    case 1:
  2043.     X    underline(0);
  2044.     X    break;
  2045.     X    case 2:
  2046.     X    StandOut(0);
  2047.     X    break;
  2048.     X    }
  2049.     X    return;
  2050.     X}
  2051. SHAR_AND_ENJOY
  2052. if test 1845 -ne "`wc -c < 'center.c'`"
  2053. then
  2054.     echo shar: error transmitting "'center.c'" '(should have been 1845 characters)'
  2055. fi
  2056. fi # end of overwriting check
  2057. echo shar: extracting "'examp.c'" '(1999 characters)'
  2058. if test -f 'examp.c'
  2059. then
  2060.     echo shar: will not over-write existing file "'examp.c'"
  2061. else
  2062. sed 's/^    X//' << \SHAR_AND_ENJOY > 'examp.c'
  2063.     X#include <stdio.h>
  2064.     X#include <term.h>
  2065.     X
  2066.     Xmain()
  2067.     X
  2068.     X{
  2069.     X    int num1, num2;
  2070.     X    float fnum1, fnum2;
  2071.     X    char HospNum[9];
  2072.     X    char text[20];
  2073.     X    static char *table[] =
  2074.     X    {
  2075.     X    "Number one",
  2076.     X    "Number two",
  2077.     X    "And even yet another",
  2078.     X    "two turtle moves",
  2079.     X    "a partridge in a directory tree"
  2080.     X    };
  2081.     X
  2082.     X
  2083.     X    if(InitTerm() != 0)
  2084.     X    printf("InitTerm failed\n");
  2085.     X    page();
  2086.     X
  2087.     X    printf("Here are your choices -->");
  2088.     X    num1 = PickOne(table, 5);
  2089.     X    printf("<--\nNumber %d was chosen\n", num1);
  2090.     X
  2091.     X    printf("Here are your choices -->");
  2092.     X    num1 = PickOne(table, 1);
  2093.     X    printf("<--\nNumber %d was chosen\n", num1);
  2094.     X
  2095.     X    printf("Enter a string -->");
  2096.     X    GetString(text, 15, 0);
  2097.     X    printf("<--\nString is %s\n", text);
  2098.     X
  2099.     X    printf("yes or no ? -->");
  2100.     X    num1 = GetBool(1);
  2101.     X    printf(",");
  2102.     X    num2 = GetBool(num1);
  2103.     X    printf("<---\n");
  2104.     X    printf("Booleans are %d, %d\n", num1, num2);
  2105.     X
  2106.     X    printf("Enter a number --->");
  2107.     X    num1 = GetInt(50, 4);
  2108.     X    printf(",");
  2109.     X    num2 = GetInt(num1, 6);
  2110.     X    printf("<---\n");
  2111.     X    printf("Numbers were %d, %d\n", num1, num2);
  2112.     X
  2113.     X    printf("Enter a number --->");
  2114.     X    fnum1 = GetFloat(50.0, 8, 5);
  2115.     X    printf(",");
  2116.     X    fnum2 = GetFloat(fnum1, 6, 2);
  2117.     X    printf("<---\n");
  2118.     X    printf("Numbers were %f, %f\n", fnum1, fnum2);
  2119.     X
  2120.     X    printf("Enter hospital number --->");
  2121.     X    GetHospNum(HospNum);
  2122.     X    printf("<---\n");
  2123.     X    printf("Number is %s\n", HospNum);
  2124.     X
  2125.     X    fflush(stdout);
  2126.     X    sleep(2);
  2127.     X
  2128.     X    page();
  2129.     X    num1 = MenuPick("This is a demo of MenuPick", table, 5);
  2130.     X    printf("<--\nNumber %d was chosen\n", num1);
  2131.     X    sleep(2);
  2132.     X
  2133.     X
  2134.     X    page();
  2135.     X    gotoxy(15, 15);
  2136.     X    center(1, "I am normal text centered on line 1", 0);
  2137.     X    center(10, "I am underlined text centered on line 10", 1);
  2138.     X    center(20, "I am standout text centered on line 20", 2);
  2139.     X    gotoxy(1, 1);
  2140.     X    printf("+");
  2141.     X    gotoxy(80, 1);
  2142.     X    printf("+");
  2143.     X    gotoxy(40, 12);
  2144.     X    printf("+");
  2145.     X    gotoxy(1, 24);
  2146.     X    printf("+");
  2147.     X    gotoxy(79, 24);
  2148.     X    printf("+");
  2149.     X    fflush(stdout);
  2150.     X
  2151.     X    sleep(2);
  2152.     X    gotoxy(1, 24);
  2153.     X    exit(0);
  2154.     X}
  2155. SHAR_AND_ENJOY
  2156. if test 1999 -ne "`wc -c < 'examp.c'`"
  2157. then
  2158.     echo shar: error transmitting "'examp.c'" '(should have been 1999 characters)'
  2159. fi
  2160. fi # end of overwriting check
  2161. echo shar: extracting "'gotoxy.c'" '(1077 characters)'
  2162. if test -f 'gotoxy.c'
  2163. then
  2164.     echo shar: will not over-write existing file "'gotoxy.c'"
  2165. else
  2166. sed 's/^    X//' << \SHAR_AND_ENJOY > 'gotoxy.c'
  2167.     X
  2168.     Xvoid gotoxy(col, line)
  2169.     Xint col, line;
  2170.     X
  2171.     X/*
  2172.     X ---------------------------------------------------------------------------
  2173.     X 
  2174.     X   Last revision - 
  2175.     X     29 March 1984 - GWS
  2176.     X 
  2177.     X 
  2178.     X   NAME
  2179.     X     gotoxy - move the cursor to the requested position
  2180.     X 
  2181.     X   SYNOPSIS
  2182.     X    void gotoxy(col, line) 
  2183.     X    int col, line;
  2184.     X 
  2185.     X   DESCRIPTION
  2186.     X    Uses termcap(3x) routines to move cursor.  The columns and
  2187.     X    lines are numbered starting with 1.
  2188.     X 
  2189.     X   SEE ALSO
  2190.     X    termcap(3) 
  2191.     X 
  2192.     X   DIAGNOSTICS
  2193.     X    If the cursor doesn't move, it didn't work. 
  2194.     X 
  2195.     X   AUTHOR
  2196.     X     George W. Sherouse
  2197.     X     29 March 1984
  2198.     X 
  2199.     X ---------------------------------------------------------------------------
  2200.     X*/
  2201.     X
  2202.     X{
  2203.     X    static called = 0;
  2204.     X    static char id[] = "cm", cm_str[20];
  2205.     X    static char *point = cm_str, **point2 = &point;
  2206.     X    extern char bp[1024];
  2207.     X    int tgetent();
  2208.     X    int tputs();
  2209.     X    int putchar();
  2210.     X    char *tgoto();
  2211.     X    char str[20];
  2212.     X    int loop;
  2213.     X
  2214.     X    if (!called)
  2215.     X    {
  2216.     X    tgetstr(id, point2);
  2217.     X    called++;
  2218.     X    }
  2219.     X
  2220.     X    for (loop = 0; loop < 20; loop++)
  2221.     X    str[loop] = cm_str[loop];
  2222.     X
  2223.     X
  2224.     X    (void) tputs(tgoto(str, col - 1, line - 1), 1, putchar);
  2225.     X    return;
  2226.     X}
  2227. SHAR_AND_ENJOY
  2228. if test 1077 -ne "`wc -c < 'gotoxy.c'`"
  2229. then
  2230.     echo shar: error transmitting "'gotoxy.c'" '(should have been 1077 characters)'
  2231. fi
  2232. fi # end of overwriting check
  2233. echo shar: extracting "'page.c'" '(813 characters)'
  2234. if test -f 'page.c'
  2235. then
  2236.     echo shar: will not over-write existing file "'page.c'"
  2237. else
  2238. sed 's/^    X//' << \SHAR_AND_ENJOY > 'page.c'
  2239.     X
  2240.     Xvoid page()
  2241.     X
  2242.     X/*
  2243.     X ---------------------------------------------------------------------------
  2244.     X 
  2245.     X   Last revision - 
  2246.     X     29 March 1984 - GWS
  2247.     X 
  2248.     X 
  2249.     X   NAME
  2250.     X     page - page the terminal
  2251.     X 
  2252.     X   SYNOPSIS
  2253.     X    void page() 
  2254.     X 
  2255.     X   DESCRIPTION
  2256.     X    Uses termcap(3x) routines to clear terminal screen. 
  2257.     X 
  2258.     X   SEE ALSO
  2259.     X    termcap(3) 
  2260.     X 
  2261.     X   DIAGNOSTICS
  2262.     X    If the screen doesn't clear, it didn't work. 
  2263.     X 
  2264.     X   AUTHOR
  2265.     X     George W. Sherouse
  2266.     X     29 March 1984
  2267.     X 
  2268.     X ---------------------------------------------------------------------------
  2269.     X*/
  2270.     X
  2271.     X{
  2272.     X    static called = 0;
  2273.     X    static char id[] = "cl", page_str[10];
  2274.     X    static char *point = page_str, **point2 = &point;
  2275.     X    extern char bp[1024];
  2276.     X    int tgetent(), tputs();
  2277.     X    int putchar();
  2278.     X
  2279.     X    if (!called)
  2280.     X    {
  2281.     X    tgetstr(id, point2);
  2282.     X    called++;
  2283.     X    }
  2284.     X
  2285.     X    (void) tputs(page_str, 1, putchar);
  2286.     X    return;
  2287.     X}
  2288. SHAR_AND_ENJOY
  2289. if test 813 -ne "`wc -c < 'page.c'`"
  2290. then
  2291.     echo shar: error transmitting "'page.c'" '(should have been 813 characters)'
  2292. fi
  2293. fi # end of overwriting check
  2294. echo shar: extracting "'underline.c'" '(1093 characters)'
  2295. if test -f 'underline.c'
  2296. then
  2297.     echo shar: will not over-write existing file "'underline.c'"
  2298. else
  2299. sed 's/^    X//' << \SHAR_AND_ENJOY > 'underline.c'
  2300.     X
  2301.     Xvoid underline(on_or_off)
  2302.     Xint on_or_off;
  2303.     X
  2304.     X
  2305.     X/*
  2306.     X ---------------------------------------------------------------------------
  2307.     X 
  2308.     X   Last revision - 
  2309.     X     30 March 1984 - GWS
  2310.     X 
  2311.     X 
  2312.     X   NAME
  2313.     X     underline - set or clear terminal underline mode
  2314.     X 
  2315.     X   SYNOPSIS
  2316.     X    void underline(on_or_off) 
  2317.     X    int on_or_off;
  2318.     X 
  2319.     X   DESCRIPTION
  2320.     X    Uses termcap(3x) routines to set terminal mode. 
  2321.     X 
  2322.     X   SEE ALSO
  2323.     X    termcap(3) 
  2324.     X 
  2325.     X   DIAGNOSTICS
  2326.     X    If the mode doesn't change, it didn't work. 
  2327.     X 
  2328.     X   AUTHOR
  2329.     X     George W. Sherouse
  2330.     X     30 March 1984
  2331.     X 
  2332.     X ---------------------------------------------------------------------------
  2333.     X*/
  2334.     X
  2335.     X{
  2336.     X    static int called = 0;
  2337.     X    static char us_id[] = "us", ue_id[] = "ue", us_str[10], ue_str[10];
  2338.     X    static char *us_point = us_str, **us_point2 = &us_point;
  2339.     X    static char *ue_point = ue_str, **ue_point2 = &ue_point;
  2340.     X    extern char bp[1024];
  2341.     X    int tgetent(), tputs();
  2342.     X    int putchar();
  2343.     X
  2344.     X    if (!called)
  2345.     X    {
  2346.     X    tgetstr(us_id, us_point2);
  2347.     X    tgetstr(ue_id, ue_point2);
  2348.     X    called++;
  2349.     X    }
  2350.     X
  2351.     X    if (on_or_off)
  2352.     X        (void) tputs(us_str, 1, putchar);
  2353.     X    else
  2354.     X        (void) tputs(ue_str, 1, putchar);
  2355.     X    return;
  2356.     X}
  2357. SHAR_AND_ENJOY
  2358. if test 1093 -ne "`wc -c < 'underline.c'`"
  2359. then
  2360.     echo shar: error transmitting "'underline.c'" '(should have been 1093 characters)'
  2361. fi
  2362. fi # end of overwriting check
  2363. #    End of shell archive
  2364. exit 0
  2365.  
  2366.  
  2367.